package cn.starlightsoftware.sherly.controller.admin.auth;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.starlightsoftware.sherly.controller.admin.auth.vo.LoginReqVO;
import cn.starlightsoftware.sherly.controller.admin.auth.vo.LoginRespVO;
import cn.starlightsoftware.sherly.model.Result;
import cn.starlightsoftware.sherly.service.auth.AuthService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.starlightsoftware.sherly.model.Result.success;

/**
 * @author 谷子毅
 */
@Validated
@Tag(name = "admin-认证")
@RestController
@RequestMapping("/system/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    @Operation(summary = "账号密码登录")
    public Result<LoginRespVO> login(@Valid @RequestBody LoginReqVO reqVO) {
        return success(authService.login(reqVO));
    }

    @PostMapping("/logout")
    @Operation(summary = "登出")
    public Result<?> logout() {
        authService.logout();
        return success();
    }

}
